
    /**  
    * @Title: DefaultMyBatisMapperScannerConfig.java
    * @Package com.efast.cafe.framework.mybatis
    * @Description: TODO(用一句话描述该文件做什么)
    * @author Administrator
    * @date 2018年9月15日
    * @version V1.0  
    */
    
package com.efast.cafe.framework.mybatis;

import java.util.Properties;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.efast.cafe.framework.constant.DataSourceConstant;
import com.efast.cafe.framework.utils.DBConfigUtils;

import tk.mybatis.spring.mapper.MapperScannerConfigurer;

/**
    * @ClassName: DefaultMyBatisMapperScannerConfig
    * @Description: TODO(这里用一句话描述这个类的作用)
    * @author Administrator
    * @date 2018年9月15日
    *
    */
@Configuration
@AutoConfigureAfter(DefaultMybatisAutoConfiguration.class)
public class DefaultMyBatisMapperScannerConfig {
	

	@Bean
	@Primary
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName(DataSourceConstant.DEFAULT_SQL_SESSION_FACTORY);
        mapperScannerConfigurer.setSqlSessionTemplateBeanName(DataSourceConstant.DEFAULT_SQL_SESSION_TEMPLATE);
        String defaultMapperScan = DBConfigUtils.getDefaultMapperScan();
        mapperScannerConfigurer.setBasePackage(defaultMapperScan);
        Properties properties = new Properties();//设置通用mapper的属性
        // 这里要特别注意，不要把MyMapper放到 basePackage 中，也就是不能同其他Mapper一样被扫描到。 
        properties.setProperty("mappers", CafeMapper.class.getName());
        properties.setProperty("notEmpty", "false");
        String dialect = DBConfigUtils.getDialect();
        properties.setProperty("IDENTITY", dialect);
        mapperScannerConfigurer.setProperties(properties);
        return mapperScannerConfigurer;
    }
}
